let http = require('http')
let Router = require('./router/index')

function Application() {
  this._router = new Router()
}

Application.prototype.get = function (path, ...handlers) {
  this._router.get(path, handlers)
}

Application.prototype.listen = function () {
  let server = http.createServer((req, res) => {
    // 无法匹配路由
    function done() {
      res.end(`Cannot ${req.url} ${req.method}`)
    }
    this._router.handle(req, res, done)
  })
  server.listen(...arguments)
}


module.exports = Application